package com.android.questions.ui.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;

import com.android.questions.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hx.currency.HXCurrencySDK;
import com.hx.currency.data.qa.model.QAPushAppRecord;

/**
 * FileName: PushRecordAdapter
 * Author: admin
 * Date: 2021/11/4 15:07
 * Description:
 */
public class PushRecordAdapter extends BaseQuickAdapter<QAPushAppRecord, BaseViewHolder> {

    public PushRecordAdapter() {
        super(R.layout.item_push_record);
    }

    @Override
    protected int getDefItemViewType(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(final BaseViewHolder baseViewHolder, QAPushAppRecord item) {
        AppCompatTextView tvName = baseViewHolder.getView(R.id.item_name);
        AppCompatTextView tvUid = baseViewHolder.getView(R.id.item_uid);
        AppCompatTextView tvDate = baseViewHolder.getView(R.id.item_date);
        AppCompatTextView tvState = baseViewHolder.getView(R.id.item_state);

        String name = item.getYym();
        if (!TextUtils.isEmpty(name) && name.contains("(")) {
            name = name.substring(0, name.indexOf("("));
        }
        if (!TextUtils.isEmpty(name)) {
            tvName.setText(name);
        }

        String pui = item.getPui();
        if (!TextUtils.isEmpty(pui)) {
            tvUid.setText("ID: " + HXCurrencySDK.getDecryptUserId(pui));
        }

        String sj = item.getSj();
        if (!TextUtils.isEmpty(sj)) {
            tvDate.setText("绑定时间：" + sj);
        }

        int state = item.getZt();
        String tips = "";
        if (state == 2) {
            tvState.setTextColor(ContextCompat.getColor(getContext(), R.color.Color_44CB5E));
            tips = "已完成";
        } else if (state == 1) {
            tvState.setTextColor(ContextCompat.getColor(getContext(), R.color.Color_FB5E27));
            tips = "待完成";
        }
        tvState.setText(tips);
    }
}